<?php
/*
** @introduction: 专题
** @author: 杨陈鹏
** @email: wanglong@cdlinglu.com
*/

namespace Admin\Controller\Special;

use Common\Controller\Admin\CommonController;

class IndexController extends CommonController
{

    /*
     ** @introduction: 专题列表
     ** @author: 杨陈鹏
     ** @email: wanglong@cdlinglu.com
     */
    public function lists()
    {

        $logic = D('Common/Special','Logic');

        $this->page = I('post.page',1);

        $this->nums = 20;

        $data = $logic::getData([],'','create_time desc,likes desc',$this->page, $this->nums);

        $this->data = $data['data'];

        $this->total = $data['total'];

        $this->display();

    }
    /*
     ** @introduction: 专题评论列表
     ** @author: 杨陈鹏
     ** @email: wanglong@cdlinglu.com
     */

    public function commentLists()
    {

        $this->special_id = I('param.id');

        $this->page = I('post.page',1);

        $this->pu = I('post.pu');

        $this->nums = 20;


        $logic = D('Common/Special','Logic');

        $data = $logic::getComment(['special_id' => $this->special_id],'*','create_time desc',$this->page,$this->nums);

        $this->data = $data['data'];

        if (!$this->data)
        {

            $this->ajaxReturn(['code' => 300, 'msg' => '暂无评论!']);

        }

        $this->total = $data['total'];

        $this->display();

    }
    /*
     ** @introduction: 专题评论列表
     ** @author: 杨陈鹏
     ** @email: wanglong@cdlinglu.com
     */

    public function deleteComment()
    {

        $id = I('param.id');

        $logic = D('Common/Special','Logic');

        if($logic::$model_comment->where(['id' => $id])->delete())
            $this->ajaxReturn(['code' => 200 ,'msg' => '删除成功']);

        $this->ajaxReturn(['code' => 300 ,'msg' => '删除失败']);


    }

    /*
     ** @introduction: 发布专题
     ** @author: 杨陈鹏
     ** @email: wanglong@cdlinglu.com
     */
    public function create()
    {

        $data = I('post.data', '', false);

        if ($data) {

            $logic = D('Common/Special','Logic');

            $this->ajaxReturn($logic::create($data));

        }

        $this->display();

    }
    /*
     ** @introduction:
     ** @author: 杨陈鹏
     ** @email: wanglong@cdlinglu.com
     */
    public function update()
    {

        $data = I('post.data');

        $this->page = I('page');

        $this->id = I('post.id');

        $logic = D('Common/Special','Logic');

        if ( $data ) {

            $logic = D('Common/Special','Logic');

            $id = $data['id'];

            unset($data['id']);

            $this->ajaxReturn($logic::update(['id' => $id],$data));

        }

        $data = $logic::getOneData($this->id,'*',false);

        $this->data = $data['data'];


        $this->display();

    }

}